﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace FMS.Formulation.Licensing.Engine
{

    internal class CheckTS
    {
        public struct OSVERSIONINFOEX
        {
            public int dwOSVersionInfoSize;

            public int dwMajorVersion;

            public int dwMinorVersion;

            public int dwBuildNumber;

            public int dwPlatformId;

            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
            public string szCSDVersion;

            public short wServicePackMajor;

            public short wServicePackMinor;

            public ushort wSuiteMask;

            public byte wProductType;

            public byte wReserved;
        }

        internal const ushort VER_SUITE_TERMINAL = 16;

        internal const ushort VER_SUITE_SINGLEUSERTS = 256;

        public static bool IsTerminalServerInstalled
        {
            get
            {
                OSVERSIONINFOEX o = default(OSVERSIONINFOEX);
                o.dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX));
                GetVersionEx(ref o);
                if ((o.wSuiteMask & 0x10) != 0)
                {
                    if ((o.wSuiteMask & 0x100) == 0)
                    {
                        return true;
                    }
                    return false;
                }
                return false;
            }
        }

        [DllImport("kernel32.Dll")]
        public static extern short GetVersionEx(ref OSVERSIONINFOEX o);

        public static string GetSuiteMask()
        {
            OSVERSIONINFOEX o = default(OSVERSIONINFOEX);
            o.dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX));
            GetVersionEx(ref o);
            return o.wSuiteMask.ToString();
        }
    }

}
